import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store/index'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import(/* webpackChunkName: "Home" */ '../views/Home.vue'),
    children: [
      {
        path: '/',
        name: 'index',
        component: () => import(/* webpackChunkName: "Index" */ '../components/Home/Index')
      },
      {
        path: '/user',
        name: 'user',
        component: () => import(/* webpackChunkName: "User" */ '../views/user/index')
      },
      {
        path: '/role',
        name: 'role',
        component: () => import(/* webpackChunkName: "User" */ '../views/permission/role')
      },
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.afterEach((to) => {
  store.dispatch('home/menuSelect', to.path).then()
})


export default router
